Skip to content

Reduce TCP channel async wait allocations#3794

Draft
Copilot wants to merge 5 commits into
masterfrom
copilot/fix-issue-3362
Draft

Reduce TCP channel async wait allocations#3794
Copilot wants to merge 5 commits into
masterfrom
copilot/fix-issue-3362

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 21, 2026

  • Update IMessageSocket: remove bool Send(IMessageSocketAsyncEventArgs), MessageSocketEventArgs(), void ReadNextMessage(); add ValueTask SendAsync(ReadOnlyMemory<byte>, CancellationToken), ValueTask SendAsync(IList<ArraySegment<byte>>, CancellationToken), Task ReadNextMessageAsync(CancellationToken)
  • Rewrite TcpMessageSocket: replace SocketAsyncEventArgs-based state machine with Socket.ReceiveAsync(Memory<byte>) async read loop and Socket.SendAsync(ReadOnlyMemory<byte>) writes (with .NET Framework fallback via TaskCompletionSource + SocketAsyncEventArgs)
  • Refactor UaSCBinaryChannel.BeginWriteMessage: remove OnWriteComplete, replace with fire-and-forget SendAsync + CompleteWriteAsync continuation helper
  • Update all ReadNextMessage() call sites in TcpListenerChannel, TcpServerChannel, UaSCBinaryClientChannelSocket.ReadNextMessageAsync()
  • Build clean: 0 warnings, 0 errors
  • All 6639 core tests pass
  • Code review: no issues
  • CodeQL: no alerts

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

- IMessageSocket: remove bool Send(IMessageSocketAsyncEventArgs),
  ReadNextMessage(), and MessageSocketEventArgs(); add ValueTask SendAsync
  overloads and Task ReadNextMessageAsync(CancellationToken)
- TcpMessageSocket: replace SocketAsyncEventArgs state-machine with a
  clean async receive loop (ReadNextMessageAsync/ReceiveExactAsync/
  ReceiveAsync) and ValueTask send path (SendAsync/SendAllAsync/
  SendOnceAsync). Modern path uses Socket.ReceiveAsync(Memory<byte>)
  and Socket.SendAsync(ReadOnlyMemory<byte>); .NET Framework path wraps
  SocketAsyncEventArgs in TaskCompletionSource.
- UaSCBinaryChannel: replace BeginWriteMessage + OnWriteComplete with
  BeginWriteMessage that fires-and-forgets a ValueTask send and handles
  completion via CompleteWriteAsync continuation helper
- TcpListenerChannel, TcpServerChannel, UaSCBinaryClientChannel: update
  ReadNextMessage() call sites to ReadNextMessageAsync() (fire-and-forget)"

Agent-Logs-Url: https://github.com/OPCFoundation/UA-.NETStandard/sessions/2b878f3d-1010-4e94-8f65-400556548045

Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Copilot AI requested a review from romanett May 21, 2026 12:35
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 60.90909% with 86 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.95%. Comparing base (df24255) to head (10f7f7f).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
Stack/Opc.Ua.Core/Stack/Tcp/TcpMessageSocket.cs 57.89% 38 Missing and 10 partials ⚠️
Stack/Opc.Ua.Core/Stack/Tcp/UaSCBinaryChannel.cs 40.90% 21 Missing and 5 partials ⚠️
...ack/Opc.Ua.Core/Stack/Tcp/ChannelAsyncOperation.cs 80.00% 9 Missing and 2 partials ⚠️
...k/Opc.Ua.Core/Stack/Tcp/UaSCBinaryClientChannel.cs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3794      +/-   ##
==========================================
- Coverage   72.00%   71.95%   -0.05%     
==========================================
  Files         677      677              
  Lines      130752   130745       -7     
  Branches    22261    22254       -7     
==========================================
- Hits        94143    94079      -64     
- Misses      29946    29994      +48     
- Partials     6663     6672       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants